package odgs.app;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyVetoException;
import java.beans.VetoableChangeListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import org.jfree.ui.about.SystemProperties;


public class SwingUtil 
{
	public static JFrame createJFrameOnExit(int width, int height) 
	{
		JFrame f = new JFrame();
		f.setSize(width, height);
		f.getContentPane().setLayout(new BorderLayout());
		f.setVisible(true);
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		return f;
	}

	public static JFrame createJFrameOnDispose(int width, int height)
	{
		JFrame f = new JFrame();
		f.setSize(width, height);
		f.getContentPane().setLayout(new BorderLayout());
		f.setVisible(true);
		f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		return f;
	}

	public static void showCiritalErrorDialog(JFrame frame, String msg) {
		final JOptionPane optionPane = new JOptionPane(msg,JOptionPane.ERROR_MESSAGE);
        final JDialog dialog = new JDialog(frame, "Critical Error!!", true);
        dialog.setContentPane(optionPane);
        dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
        dialog.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent we) {
            	System.exit(0);
            }
        });
        
        optionPane.addPropertyChangeListener(
                new PropertyChangeListener() {
                    public void propertyChange(PropertyChangeEvent e) {
                        String prop = e.getPropertyName();
                        if (dialog.isVisible() && (e.getSource() == optionPane)&&(JOptionPane.VALUE_PROPERTY.equals(prop))) 
                        	dialog.setVisible(false);
                    }
                });
        dialog.pack();
        dialog.setLocationRelativeTo(frame);
        dialog.setVisible(true);
        System.exit(0);
	}

	public static void showErrorDialog(JFrame frame, String ment) {
		final JOptionPane optionPane = new JOptionPane(ment,JOptionPane.ERROR_MESSAGE);
        final JDialog dialog = new JDialog(frame, "Error!!", true);
        dialog.setContentPane(optionPane);
        dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
        optionPane.addPropertyChangeListener(
                new PropertyChangeListener() {
                    public void propertyChange(PropertyChangeEvent e) {
                        String prop = e.getPropertyName();
                        if (dialog.isVisible() && (e.getSource() == optionPane)&&(JOptionPane.VALUE_PROPERTY.equals(prop))) 
                        	dialog.setVisible(false);
                    }
                });
        dialog.pack();
        dialog.setLocationRelativeTo(frame);
        dialog.setVisible(true);
	}

	public static String showInputDialog(Container frame, String ment) {
		return  JOptionPane.showInputDialog(frame, ment);
	}

	public static int showYesOrNoDialog(JFrame frame, String ment)
	{
        return JOptionPane.showConfirmDialog(frame,ment,"Yes or No", JOptionPane.YES_NO_OPTION);
	}
}